home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / k3bvalidators.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-05-27  |  3.5 KB  |  132 lines

  1. /* 
  2.  *
  3.  * $Id: k3bvalidators.h 619556 2007-01-03 17:38:12Z trueg $
  4.  * Copyright (C) 2003-2007 Sebastian Trueg <trueg@k3b.org>
  5.  *
  6.  * This file is part of the K3b project.
  7.  * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
  8.  *
  9.  * This program is free software; you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation; either version 2 of the License, or
  12.  * (at your option) any later version.
  13.  * See the file "COPYING" for the exact licensing terms.
  14.  */
  15.  
  16. #ifndef _K3B_VALIDATORS_H_
  17. #define _K3B_VALIDATORS_H_
  18.  
  19. #include <qvalidator.h>
  20. #include "k3b_export.h"
  21.  
  22.  
  23. /**
  24.  * Simple validator that validates a string char by char
  25.  */
  26. class LIBK3B_EXPORT K3bCharValidator : public QValidator
  27. {
  28.  public:
  29.   K3bCharValidator( QObject* parent = 0, const char* name = 0 );
  30.  
  31.   virtual State validateChar( const QChar& ) const = 0;
  32.  
  33.   virtual State validate( QString& s, int& pos ) const;
  34.  
  35.   /**
  36.    * Replaces all invalid chars with the repplace char
  37.    */
  38.   virtual void fixup( QString& ) const;
  39.  
  40.   /**
  41.    * Default to '_'
  42.    */
  43.   void setReplaceChar( const QChar& c ) { m_replaceChar = c; }
  44.  
  45.  private:
  46.   QChar m_replaceChar;
  47. };
  48.  
  49.  
  50. class LIBK3B_EXPORT K3bLatin1Validator : public K3bCharValidator
  51. {
  52.  public:
  53.   K3bLatin1Validator( QObject* parent = 0, const char* name = 0 );
  54.  
  55.   virtual State validateChar( const QChar& ) const;
  56. };
  57.  
  58.  
  59. class LIBK3B_EXPORT K3bAsciiValidator : public K3bLatin1Validator
  60. {
  61.  public:
  62.   K3bAsciiValidator( QObject* parent = 0, const char* name = 0 );
  63.  
  64.   virtual State validateChar( const QChar& ) const;
  65. };
  66.  
  67.  
  68. /**
  69.  * The K3bValidator extends QRegExpValidator with a fixup method
  70.  * that just replaces all characters that are not allowed with the 
  71.  * replace character. It only makes sense for QRegExps that simply
  72.  * allow or forbid some characters.
  73.  */
  74. class LIBK3B_EXPORT K3bValidator : public QRegExpValidator
  75. {
  76.  public:
  77.   K3bValidator( QObject* parent, const char * name = 0 );
  78.   K3bValidator( const QRegExp& rx, QObject* parent, const char* name = 0 );
  79.  
  80.   void setReplaceChar( const QChar& s ) { m_replaceChar = s; }
  81.   const QChar& replaceChar() const { return m_replaceChar; }
  82.  
  83.   virtual void fixup( QString& ) const;
  84.  
  85.  private:
  86.   QChar m_replaceChar;
  87. };
  88.  
  89.  
  90. namespace K3bValidators
  91. {
  92.   /**
  93.    * just replaces all characters that are not allowed with the 
  94.    * replace character. It only makes sense for QRegExps that simply
  95.    * allow or forbid some characters.
  96.    */
  97.   LIBK3B_EXPORT QString fixup( const QString&, const QRegExp&, const QChar& replaceChar = '_' );
  98.  
  99.   /**
  100.    * Validates an ISRC code of the form "CCOOOYYSSSSS" where:
  101.    * <ul>
  102.    * <li>C: country code (upper case letters or digits)</li>
  103.    * <li>O: owner code (upper case letters or digits)</li>
  104.    * <li>Y: year (digits)</li>
  105.    * <li>S: serial number (digits)</li>
  106.    * </ul>
  107.    */
  108.   LIBK3B_EXPORT K3bValidator* isrcValidator( QObject* parent = 0, const char* name = 0 );
  109.   
  110.   /**
  111.    * This needs to be replaced by something better in the future...
  112.    * Even the name sucks!
  113.    */
  114.   LIBK3B_EXPORT K3bValidator* iso9660Validator( bool allowEmpty = true, QObject* parent = 0, const char* name = 0 );
  115.  
  116.   /**
  117.    * (1) d-characters are: A-Z, 0-9, _ (see ISO-9660:1988, Annex A, Table 15)
  118.    * (2) a-characters are: A-Z, 0-9, _, space, !, ", %, &, ', (, ), *, +, ,, -, ., /, :, ;, <, =, >, ? 
  119.    * (see ISO-9660:1988, Annex A, Table 14)
  120.    */
  121.   enum Iso646Type {
  122.     Iso646_a, 
  123.     Iso646_d 
  124.   };
  125.  
  126.   LIBK3B_EXPORT K3bValidator* iso646Validator( int type = Iso646_a, 
  127.                  bool AllowLowerCase = false, 
  128.                  QObject* parent = 0, const char* name = 0 );
  129. }
  130.  
  131. #endif
  132.